package com.jackstraw.jack_base.rules.service.impl;

import com.jackstraw.jack_base.datasource.common.aspect.annotation.DataSourceNameCut;
import com.jackstraw.jack_base.datasource.common.entity.enums.DataSourceTypeEnum;
import com.jackstraw.jack_base.datasource.mybatis.base.service.impl.MyBatisServiceImpl;
import com.jackstraw.jack_base.rules.dao.database.RelationSargDao;
import com.jackstraw.jack_base.rules.entity.bo.RelationSargBo;
import com.jackstraw.jack_base.rules.entity.bo.SceneActuatorBo;
import com.jackstraw.jack_base.rules.entity.mapstruct.RelationSargMapstruct;
import com.jackstraw.jack_base.rules.entity.po.RelationSargKeyPo;
import com.jackstraw.jack_base.rules.entity.po.RelationSargPo;
import com.jackstraw.jack_base.rules.entity.po.RelationSargPoExample;
import com.jackstraw.jack_base.rules.service.RelationSargService;
import com.jackstraw.jack_base.rules.service.SceneActuatorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * 场景规则组关系表  service实现类
 *
 * @author zhaozhao 945514650@qq.com
 * @since version:1.0 generatorDate:2022-12-04 14:28:29
 */
@Slf4j
@DataSourceNameCut(dataSourceName = "dataBaseName1", dataSourceTypeEnum = DataSourceTypeEnum.database)
public class RelationSargServiceImpl
        extends MyBatisServiceImpl<RelationSargDao, RelationSargPo, RelationSargBo, RelationSargKeyPo<RelationSargPo>, RelationSargPoExample>
        implements RelationSargService {

    @Autowired
    private RelationSargMapstruct relationSargMapstruct;


    @Override
    protected RelationSargPoExample pe(Map<String, Object> params) {
        RelationSargPoExample pe = super.pe(params);
        //默认查询主键
        pe.addKey(params);
        return pe;
    }

    @Override
    public List<RelationSargBo> queryAllBySceneId(Long sceneActuatorId) {
        RelationSargPoExample relationSargPoExample = new RelationSargPoExample();
        relationSargPoExample.createCriteria()
                .andSceneActuatorIdEqualTo(sceneActuatorId);
        List<RelationSargPo> relationSargPos = this.getDao().selectByExample(relationSargPoExample);
        return relationSargMapstruct.boToS(relationSargPos);
    }
}
